<?php
class Match extends AppModel
{
	var $name = "Match";
	
	var $virtualFields = array(
		'viewdate' => "DATE_FORMAT(`date`, '%d-%m-%Y %H:%i')",
		'dateonly' => "DATE_FORMAT(`date`, '%d-%m')"
	);
	
	function getData($result)
	{
		if($result == "played") {
			return $this->find("all", array(
				"fields" => array(
					"Match.hometeam",
					"Match.visitorteam",
					"Match.viewdate",
					"Match.result",
				),
				"conditions" => array(
					"Match.date <= NOW()"
				),
				"order" => "date DESC"
			));
		}
		else {
			return $this->find("all", array(
				"fields" => array(
					"Match.hometeam",
					"Match.visitorteam",
					"Match.viewdate"
				),
				"conditions" => array(
					"Match.date > NOW()"
				),
				"order" => "date ASC"
			));
		}
	}
	
	function getUpcoming()
	{
		return $this->find("all", array(
			"fields" => array(
				"Match.hometeam",
				"Match.visitorteam",
				"Match.dateonly"
			),
			"conditions" => array(
				"Match.date > NOW()"
			),
			"order" => "date ASC",
			"limit" => "0, 3"
		));
	}

	function getPlayed()
	{
		return $this->find("all", array(
			"fields" => array(
				"Match.hometeam",
				"Match.visitorteam",
				"Match.result"
			),
			"conditions" => array(
				"Match.date <= NOW()"
			),
			"order" => "date DESC",
			"limit" => "0, 3"
		));
	}
}